<!doctype html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>分类</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #app {
            display: flex;
        }

        .wrap {
            display: flex;
            width: auto;
            height: 100vh;
            padding: 0;
            background: #fff;
            line-height: 2rem;
            overflow-y: auto;
        }

        .item {
            width: 7rem;
            text-align: center;
            padding: .75rem 0;
        }

        .active {
            background: #0689FB;
            color: #fff;
        }

        .close_win {
            flex: 1;
        }

        .ellipsis-1 {
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="wrap">
            <div>
                <template v-for="o,i in parentList">
                  <div class="item ellipsis-1" :class="{active:i===parentIndex}" @click="parentClick(i)">
                      {{o.work_cate_name}}
                  </div>
              </template>
            </div>
            <div>
                <template v-for="o,i in childList">
                  <div class="item ellipsis-1" :class="{active:i===childIndex}" @click="childClick(i)">
                      {{o.work_cate_name}}
                  </div>
                </template>
            </div>
        </div>
        <div class="close_win" @click="close_f()"></div>
    </div>
</body>
<script src="../../script/api.js" charset="utf-8"></script>
<script src="../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../script/common/common.js" charset="utf-8"></script>
<script src="../../script/common/config.js" charset="utf-8"></script>
<script src="../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        vm.get_data();
    }
    var vm = new Vue({
        el: "#app",
        data: {
            parentList: [{
                'work_cate_id': 0,
                'parent_id': 0,
                'work_cate_name': '全部分类'
            }],
            childList: [],

            parentIndex: 0,
            childIndex: 0,
        },
        methods: {
            get_data() {
                var self = this;
                _ajax(Config.api.WorkCateGetParentList, {}, function(res) {
                    if (res.code === 200) {
                        self.parentList = self.parentList.concat(res.data);
                    }
                })
            },
            parentClick(i) {
                var self = this;
                self.parentIndex = i;
                var data = self.parentList[self.parentIndex];
                if (data.work_cate_id === 0) {
                    self.close_frm();
                } else {
                    _ajax(Config.api.WorkCateGetChildList, {
                        parent_id: data.work_cate_id
                    }, function(res) {
                        if (res.code === 200) {
                            self.childIndex = 0;
                            self.childList = res.data;
                        }
                    })
                }
            },
            childClick(i) {
                this.childIndex = i;
                this.close_frm();
            },
            close_frm() {
                var parentData = this.parentList[this.parentIndex];
                if (parentData.work_cate_id === 0) {
                    api.execScript({
                        name: api.pageParam.name,
                        frameName: api.pageParam.frameName,
                        script: 'setType()'
                    });
                } else {
                    var childData = this.childList[this.childIndex];
                    api.execScript({
                        name: api.pageParam.name,
                        frameName: api.pageParam.frameName,
                        script: 'setType(' + JSON.stringify(parentData) + ',' + JSON.stringify(childData) + ')'
                    });
                }
                close_f();
            }
        }
    });
</script>

</html>
